<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@include file="init.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Edit Category Admin</title>
</head>
<body>
<div class="master-wrapper-content">
	<jsp:include page="heading.jsp"></jsp:include>
	<%
		System.out.println(session.getAttribute("roleId"));
		if(session.getAttribute("roleId") == null || String.valueOf(session.getAttribute("roleId")).equalsIgnoreCase("2")) {
			%>
				<h3 style="color: red">Không đủ quyền để truy cập</h3>
			<%
		}
		else {
	%>
			<jsp:include page="CategoryAdmin.jsp"></jsp:include>
			<div class="container-right">
			<%
				int categoryId = Integer.valueOf(request.getParameter("categoryId"));
				
				Category category = dataManager.getCategoryWithCategoryId(categoryId);
				
				List<String> categoryNames = new ArrayList<String>();
				List<Integer> categoryIds = new ArrayList<Integer>();
				
				dataManager.getTreeStructure(categoryIds, categoryNames);
				%>
				<form action="UpdateCategoryServlet" method="post">
					<input type="hidden" name="categoryId" value="<%=String.valueOf(categoryId) %>" />
					ParentName : 
					<select name="categoryParentId">
					<%
						for(int i = 0; i < categoryIds.size(); ++ i) {
							if(category.getCategoryParentId() == categoryIds.get(i)) {
							%>
								<option value="<%=categoryIds.get(i) %>" selected="selected"><%=categoryNames.get(i).replace(" ", "&nbsp") %></option>
							<%
							}
							else {
							%>
								<option value="<%=categoryIds.get(i) %>"><%=categoryNames.get(i).replace(" ", "&nbsp") %></option>
							<%
							}
							
						}
					%>
					</select>
					
					<table>			
						<tr>
							<td>Category Name : </td>
							<td><input type="text" name="categoryName" value="<%=category.getCategoryName() %>" /></td>
						</tr>
						<tr>
							<td><input type="submit" value="Edit Category" /></td>
						</tr>
					</table>
				</form>
			</div>
			<div class="clear"></div>
	<%
		}
%>
</div>
</body>
</html>